#include "parser.h"

bool parser(char input[][ARGV_LEN], char output[], int size)
{
    bool ret = true;
    if(!strcmp(input[0], "dir"))
        generateShCmd("ls", input, output, size);
    else if(!strcmp(input[0], "rename"))
        generateShCmd("mv", input, output, size);
    else if(!strcmp(input[0], "move"))
        generateShCmd("mv", input, output, size);
    else if(!strcmp(input[0], "del"))
        generateShCmd("rm", input, output, size);
    else if(!strcmp(input[0], "cd"))
    {
        if(input[1][0] == 0)
            generateShCmd("pwd", input, output, size);
        else
            generateShCmd("cd", input, output, size);
    }
    else if(!strcmp(input[0], "exit"))
    {
        generateShCmd("exit", input, output, size);
        ret = false;
    }
    else
    {
        generateShCmd(":", input, output, size); // To avoid to get some
    }                                           // dangerous input.
    return ret;
}

bool generateShCmd(char cmp[], char input[][ARGV_LEN], char output[], int size)
{
    bool ret = false;
    int len = ARGV_LEN - 1;
    memset(output, 0, ARGV_LEN);
    strcpy(output, cmp);
    strcat(output, " ");
    for(int i = 1; i < size; i++)
    {
        strcat(output, input[i]);
        strcat(output, " ");
    }
    return ret;
}
